/**
 * Created With IntelliJ IDEA
 * Description:牛客网：BM52 数组中只出现一次的两个数字
 * https://www.nowcoder.com/practice/389fc1c3d3be4479a154f63f495abff8?tpId=295&tqId=1375231&ru=/exam/oj&qru=/ta/format-top101/question-ranking&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3D%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D295
 * User: DELL
 * Data: 2022-11-03
 * Time: 20:24
 */
import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * @param array int整型一维数组
     * @return int整型一维数组
     */
    public int[] FindNumsAppearOnce (int[] array) {
        //先将数组中所有数字进行异或
        int num = 0;
        for (int x: array) {
            num ^= x;
        }
        //找到tmp最低的数值为1的bit位
        int tmp = 1;
        while ((num & tmp) == 0) {
            tmp <<= 1;
        }
        //依据找到的bit位是否为1将原数组分开，分别异或运算
        int num1 = 0;
        int num2 = 0;
        for (int j : array) {
            if ((j & tmp) == 0) {
                num1 ^= j;
            } else {
                num2 ^= j;
            }
        }
        //整理次序，小的元素放前面
        int[] arr = new int[2];
        arr[0] = Math.min(num1, num2);
        arr[1] = Math.max(num1, num2);
        return arr;
    }
}